package bestv.kss.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("deprecation")
public class HttpXmlClient {
	final static Logger logger = LoggerFactory.getLogger(HttpXmlClient.class);

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		HttpClient httpclient = new DefaultHttpClient();

		// 你的URL
		HttpPost httppost = new HttpPost(
				"http://localhost:8080/liveManager/eventRecordController.do?OnCallBackEvent");
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			// Your DATA
			nameValuePairs.add(new BasicNameValuePair("EventType", "1"));
			nameValuePairs.add(new BasicNameValuePair("ChannelCode", "nba1"));
			nameValuePairs.add(new BasicNameValuePair("OriginName",
					"Dev_Origin24"));
			nameValuePairs.add(new BasicNameValuePair("Result", "1"));
			nameValuePairs.add(new BasicNameValuePair("EventHappenedTime",
					"150206135000"));
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			HttpResponse response;
			response = httpclient.execute(httppost);
			/* 若状态码为200 ok */
			if (response.getStatusLine().getStatusCode() == 200) {
				String strResult = EntityUtils.toString(response.getEntity());
				System.out.println(strResult);
			}
			// logger.info(strResult);
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
